

function CreateMusic ( )
    LoadMusic ( 1, "music\SaucerScuffle.mp3" )
    SetMusicSystemVolume ( 50 )
    PlayMusic ( 1, 1 )
endfunction

function LoadAssets ( )
    print ("Loading assets... This may take a moment...")
    sync ( )
    // Load arena images
    if g_iSkyImage                  = 0 then g_iSkyImage                    = LoadImage ( "arena/Sky.png" )
    if g_iPlatformImage [ pSmall ]  = 0 then g_iPlatformImage   [ pSmall ]  = LoadImage ( "arena/SmallPlatform.png" )
    if g_iPlatformImage [ pMedium ] = 0 then g_iPlatformImage   [ pMedium ] = LoadImage ( "arena/MediumPlatform.png" )
    if g_iPlatformImage [ pLarge ]  = 0 then g_iPlatformImage   [ pLarge ]  = LoadImage ( "arena/LargePlatform.png" )
    if g_iSpawnerImage              = 0 then g_iSpawnerImage                = LoadImage ( "arena/SaucerSpawn.png" )
    if g_iBalloonImage  [ 1 ]       = 0 then g_iBalloonImage    [ 1 ]       = LoadImage ( "arena/Balloon0000.png" )
    if g_iBalloonImage  [ 2 ]       = 0 then g_iBalloonImage    [ 2 ]       = LoadImage ( "arena/Balloon0001.png" )
    if g_iBalloonImage  [ 3 ]       = 0 then g_iBalloonImage    [ 3 ]       = LoadImage ( "arena/Balloon0002.png" )
    if g_iBalloonImage  [ 4 ]       = 0 then g_iBalloonImage    [ 4 ]       = LoadImage ( "arena/Balloon0003.png" )
    if g_iStringImage               = 0 then g_iStringImage                 = LoadImage ( "arena/String.png" )
    // Load player images
    if g_iPlayerImage   [ 1 ]       = 0 then g_iPlayerImage     [ 1 ]       = LoadImage ( "arena/FlyingShoe0000.png" )
    if g_iPlayerImage   [ 2 ]       = 0 then g_iPlayerImage     [ 2 ]       = LoadImage ( "arena/FlyingShoe0001.png" )
    if g_iPlayerImage   [ 3 ]       = 0 then g_iPlayerImage     [ 3 ]       = LoadImage ( "arena/FlyingShoe0002.png" )
    if g_iPlayerImage   [ 4 ]       = 0 then g_iPlayerImage     [ 4 ]       = LoadImage ( "arena/FlyingShoe0003.png" )
    if g_iPlayerImage   [ 5 ]       = 0 then g_iPlayerImage     [ 5 ]       = LoadImage ( "arena/FlyingShoe0004.png" )
    if g_iPlayerImage   [ 6 ]       = 0 then g_iPlayerImage     [ 6 ]       = LoadImage ( "arena/FlyingShoe0005.png" )
endfunction

function TeleportPhysicsObject(object, xValue, yValue)
    objectVelocityX = GetSpritePhysicsVelocityX(object)
    objectVelocityY = GetSpritePhysicsVelocityY(object)
    SetSpritePhysicsOff (object)
    SetSpriteX (object, xValue)
    SetSpriteY (object, yValue)
    SetSpritePhysicsOn (object, 2)
    SetSpritePhysicsVelocity (object, objectVelocityX, objectVelocityY)
endfunction

function CheckBoundary (object, x1Boundary, x2Boundary, y1Boundary, y2Boundary)
    if GetSpriteX (object) > x1Boundary then TeleportPhysicsObject (object, x2Boundary, GetSpriteY (object))
    if GetSpriteX (object) < x2Boundary then TeleportPhysicsObject (object, x1Boundary, GetSpriteY (object))
    if GetSpriteY (object) > y1Boundary then TeleportPhysicsObject (object, y2Boundary, GetSpriteX (object))
    if GetSpriteY (object) < y2Boundary then TeleportPhysicsObject (object, y1Boundary, GetSpriteX (object))
endfunction

function CapSpeed ( objectSprite, maxVel# )
    if GetSpritePhysicsVelocityX ( objectSprite ) < -maxVel# then SetSpritePhysicsVelocity ( objectSprite, -maxVel#, GetSpritePhysicsVelocityY( objectSprite ) )
    if GetSpritePhysicsVelocityX ( objectSprite ) >  maxVel# then SetSpritePhysicsVelocity ( objectSprite,  maxVel#, GetSpritePhysicsVelocityY( objectSprite ) )
endfunction
